package personStudent;

/*
 * Tags: ArrayList, Iterator, Date
 */

import java.util.*;

public class StudentTest 
{
	static final int MAX_DOB_YEAR = 2013;  //new Date().getYear();
	static final int MIN_DOB_YEAR = (MAX_DOB_YEAR-150);
	
	/*
	 * Return an string input from user
	 */
	public static String inputAString(String prompt)
	{
		Scanner s = new Scanner(System.in);
		String  returnString = "";
		
		System.out.println(prompt + "? : ");
		do
		{	
			returnString = s.nextLine();
		}while(returnString.equals(""));
		
		return returnString;
	}

	/*
	 * Return an string input from user
	 */
	public static int inputAnInteger(String prompt)
	{
		Scanner s = new Scanner(System.in);
		int  returnInteger = -1;
		
		System.out.println(prompt + "?: ");
		do
		{	
			returnInteger = s.nextInt();
		}while(returnInteger < MIN_DOB_YEAR || returnInteger > MAX_DOB_YEAR);
		
		return returnInteger;
	}
	
	//main entry
	public static void main(String[] args) 
	{
		boolean done      = false;
		ArrayList<Student> studentList = new ArrayList<Student>();
		Student studentObject = null;
		String  studentFullName, studentID;
		int     studentYearOfBirth;

		try
		{
			while(done == false)
			{	
				System.out.println("\n");

				studentFullName    = inputAString("What is the student's full name(\"exit\" when done");
				if(studentFullName.equalsIgnoreCase("exit"))
				{
					//exit while looplacheng
					done = true;
					continue;
				}
				studentID          = inputAString("What is the student's ID");
				studentYearOfBirth = inputAnInteger("What is the student's YEAR of birth");
						
				studentObject = new  Student(studentFullName, studentYearOfBirth, studentID);
				studentList.add(studentObject);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		
		System.out.println("\n" + "Total number of student(s):" + studentList.size() + "\n");
		
		//print out the student info in the student ArrayList
		for(int i=0; i < studentList.size(); i++)
		{
			System.out.println(studentList.get(i));
		}
		
		System.out.println("\nBye bye! Come back again next time!");
		System.exit(0);
	}	
}